import { request } from 'ice'
import { message } from 'antd'

const baseRequest = (url, method, data, options = {}) => {
    const token = sessionStorage.getItem('token') || '';
    if (method === 'POST') {
        return request.post(url, data, {
            headers: {
                'Token': token
            },
            ...options
        })
    } else {
        // 这里可以根据不同的请求方法进行处理
        return request.get(url, {
            params: data,
            headers: {
                'Token': token
            },
            ...options
        })
    }
}
export default baseRequest

const createGetRequest = async (url, data = {}, options = {}) => {
    try {
        return await baseRequest(url, 'GET', data, options);
    } catch (error) {
        message.error('操作失败，请稍后重试或联系管理员！')
        return {}
    }
}
const createPostRequest = async (url, data = {}) => {
    try {
        return await baseRequest(url, 'POST', data);
    } catch (error) {
        message.error('操作失败，请稍后重试或联系管理员！')
        return {}
    }
}

export {
    createGetRequest,
    createPostRequest
}